<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="rtl">|they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">^they| said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">^they |said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-0 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">t|hey said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">t^hey| said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">t^hey |said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-1 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">th|ey said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">th^ey| said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">th^ey |said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-2 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">the|y said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">the^y| said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">the^y |said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-3 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they| said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they^ said| "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they^ |said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-4 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they |said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they ^said| "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they ^said |"\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-5 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they s|aid "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they s^aid| "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they s^aid |"\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-6 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they sa|id "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they sa^id| "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they sa^id |"\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-7 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they sai|d "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they sai^d| "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they sai^d |"\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-8 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said| "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said^ "\u202Bcar| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said^ "\u202Bcar |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-9 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said |"\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said ^"\u202Bcar| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said ^"\u202Bcar |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-10 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "|\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "^\u202Bcar| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "^\u202Bcar |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-11 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202B|car \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202B^car| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202B^car |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-12 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bc|ar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bc^ar| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bc^ar |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-13 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bca|r \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bca^r| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bca^r |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-14 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bcar^ \u05D3\u05D4\u05D5| \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bcar^ |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-15 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar |\u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bcar ^\u05D3\u05D4\u05D5| \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bcar ^\u05D3\u05D4\u05D5 |\u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-16 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3|\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3^\u05D4\u05D5| \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3^\u05D4\u05D5 |\u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-17 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4|\u05D5 \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4^\u05D5| \u05D0\u05D1\u05D2\u202C."</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4^\u05D5 |\u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-18 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5| \u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5^ \u05D0\u05D1\u05D2\u202C."|</div>'
      : '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5^ |\u05D0\u05D1\u05D2\u202C."</div>',
  `${behavior} 18-19 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 |\u05D0\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 ^\u05D0\u05D1\u05D2\u202C."|</div>',
  `${behavior} 18-20 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0|\u05D1\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0^\u05D1\u05D2\u202C."|</div>',
  `${behavior} 18-21 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1|\u05D2\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1^\u05D2\u202C."|</div>',
  `${behavior} 18-22 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2|\u202C."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2^\u202C."|</div>',
  `${behavior} 18-23 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C|."</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C^."|</div>',
  `${behavior} 18-24 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C.|"</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">they said "\u202Bcar \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C.^"|</div>',
  `${behavior} 18-25 rtl left word`);
}
</script>
